package com.codejam.pagehelper.starter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.codejam.pagehelper.starter.dal.dataobject.User;
import com.codejam.pagehelper.starter.dal.mapper.IUserMapper;
import com.codejam.pagehelper.starter.service.interfaces.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jws.soap.SOAPBinding;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

@Service
public class UserServiceImpl implements IUserService {


    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<User> getUser() {

        String sql = "select * from user limit 1";
        List<User> query = jdbcTemplate.query(sql, new RowMapper<User>() {
            @Override
            public User mapRow(ResultSet resultSet, int i) throws SQLException {
                User temp = new User();
                temp.setAge(resultSet.getInt("age"));
                temp.setId(resultSet.getLong("id"));
                temp.setEmail(resultSet.getString("email"));
                temp.setName(resultSet.getString("name"));
                return temp;
            }
        });

        return query;
    }

    @Autowired
    private IUserMapper userMapper;

    @Override
    public List<User> getUserList() {


        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("id", Long.valueOf(0));
        List<User> users = userMapper.selectList(queryWrapper);

        return users;
    }

    @Override
    public String getRandomString() {

        return userMapper.getRandomString();
    }
}
